﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Action.SPI;
using T.FAS.Runtime.Base.Common;
using T.ServiceComponent.Monitor.Client;

namespace T.FAS.Runtime.Action.Engine
{
    public static class ActionEngineMonitor
    {
        #region 监控元数据
        private static string MD_ActionEngineExecuteTotalTPS = "FAS.Action.EnginieExecuteTotal.TPS";
        private static string MD_ActionEngineExecuteSuccessTPS = "FAS.Action.EngineExecuteSuccess.TPS";
        private static string MD_ActionEngineExecuteFailTPS = "FAS.Action.EngineExecuteFail.TPS";
        private static string MD_ActionEngineExecuteSuccessDuration = "FAS.Action.EngineExecuteSuccess.Duration";
        #endregion

        public static void MonitorActionEngineTotalTPS(ActionExecContext actionContext,string proxyName)
        {
            try
            {
                MonitorClient.Send(MD_ActionEngineExecuteTotalTPS, 1,
                    new Dictionary<string, string>()
                    {
                        { "ProxyName",proxyName},
                        { "Code",actionContext.MetaData.MetaDataCode },
                        { "ActionType",Convert.ToString(actionContext.ActionType)},
                        { "HostNameProcess",FASContextHelper.GetInstance().HostName+FASContextHelper.GetInstance().ProcessID}
                    });
            }
            catch
            { }
        }
        public static void MonitorActionEngineSuccessTPS(ActionExecContext actionContext, string proxyName)
        {
            try
            {
                MonitorClient.Send(MD_ActionEngineExecuteSuccessTPS, 1,
                    new Dictionary<string, string>()
                    {
                        { "ProxyName",proxyName},
                        { "Code",actionContext.MetaData.MetaDataCode },
                        { "ActionType",Convert.ToString(actionContext.ActionType)},
                        { "HostNameProcess",FASContextHelper.GetInstance().HostName+FASContextHelper.GetInstance().ProcessID}
                    });
            }
            catch
            { }
        }
        public static void MonitorActionEngineFailTPS(ActionExecContext actionContext, string proxyName)
        {
            try
            {
                MonitorClient.Send(MD_ActionEngineExecuteFailTPS, 1,
                    new Dictionary<string, string>()
                    {
                        { "ProxyName",proxyName},
                        { "Code",actionContext.MetaData.MetaDataCode },
                        { "ActionType",Convert.ToString(actionContext.ActionType)},
                        { "HostNameProcess",FASContextHelper.GetInstance().HostName+FASContextHelper.GetInstance().ProcessID}
                    });
            }
            catch
            { }
        }
        public static void MonitorActionEngineSuccessDuration(ActionExecContext actionContext, string proxyName,double duration)
        {
            try
            {
                MonitorClient.Send(MD_ActionEngineExecuteSuccessDuration, duration,
                    new Dictionary<string, string>()
                    {
                        { "ProxyName",proxyName},
                        { "Code",actionContext.MetaData.MetaDataCode },
                        { "ActionType",Convert.ToString(actionContext.ActionType)},
                        { "HostNameProcess",FASContextHelper.GetInstance().HostName+FASContextHelper.GetInstance().ProcessID}
                    });
            }
            catch
            { }
        }


    }
}
